const koa = require('koa');
const router = require('koa-router')();
const views = require('koa-views');
const serve = require('koa-static');

class MyKoa {
    app = new koa();

    constructor(views_path, static_path, extension='html') {
        this.app
            // 配置模板引擎所在的目录
            .use(views(views_path, {
                extension: extension, // 使用 HTML、EJS 等模板引擎
            }))
            // 配置静态文件目录
            .use(serve(static_path));
    }

    route(maps){
        for(let row of maps)
            router.get(row[0], row[1])
        return this
    }

    start(port = 3080) {
        this.app
            .use(router.routes())
            .listen(
                port,
                _ => console.log(`Server running on http://localhost:${port}`));
    }
}

module.exports = MyKoa
// module.exports = {
//     MyKoa,
// }
